package com.kun.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.dao.UserInfoDao;
import com.kun.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserInfoService {

    @Autowired
    private UserInfoDao userInfoDao;

    public UserInfo findById(Integer userId) {
        return userInfoDao.selectByPrimaryKey(userId);
    }
    public UserInfo login(String userName ,String userPwd){
       return  userInfoDao.login(userName,userPwd);
    }
    public Map<String ,Object> selectByPage(Integer pageNum,Integer pageSize,UserInfo userInfo){
        //通过PageHelper对象设定分页参数
        PageHelper.startPage(pageNum, pageSize);
        //当前页面的数据
        List<UserInfo> list = userInfoDao.findAll(userInfo);
        //创建PageInfo对象，并将当前页面数据传入，计算分页相关数据
        PageInfo<UserInfo> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }
    public int  insertUser(UserInfo userInfo){
        return userInfoDao.insert(userInfo);
    }
    public int batchDelete(Integer[] userIds){
        return userInfoDao.batchDelete(userIds);
    }
    public int updateUser(UserInfo userInfo){
        return userInfoDao.updateByPrimaryKeySelective(userInfo);
    }

    public List<UserInfo> exportExcel(UserInfo userInfo) {
        return userInfoDao.findAll(userInfo);
    }
    public boolean saveBatch(List<UserInfo> list){
        return userInfoDao.saveBatch(list);
    }
    public List<UserInfo> findUserName(){
        return userInfoDao.findUserName();
    }
}
